package com.mmaingenieria.MMAGestor.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

/**
 * Servlet implementation class CerrarSesion
 */
public class CerrarSesion extends InitServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CerrarSesion() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		super.doGet(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try{
			super.doPost(request, response, false);//miro si hay usuario logeado.
	        super.dispatcher = request.getRequestDispatcher(getConfigProperties().getProperty("ruta_finSesion"));//Le digo a donde tiene que ir
		    super.dispatcher.forward(request, response);//Le digo que vaya
		    if (super.usuarioSesion!=null){
		    	Logger.getLogger(this.getClass()).info("Sesion Cerrada por: " + super.usuarioSesion.getUsuario());
		    }
		}catch(Exception e){
			Logger.getLogger(this.getClass()).error("Excepcion generada cerrando sesion");
			super.dispatcher = request.getRequestDispatcher(getConfigProperties().getProperty("ruta_error"));//le dirijo a la pagina de error
		    super.dispatcher.forward(request, response);//Le digo que vaya
		}
	}
}
